#pragma once
#include "afxwin.h"

#include "Business/Policy/TrendBusiness.h"
#include "Business/QueueContext.h"
#include "Utils/FastBlockQueue.h"
// CTrendBusinessDlg dialog
class ThreadManager;
struct Command;

class CTrendBusinessDlg : public CDialog
{
	DECLARE_DYNAMIC(CTrendBusinessDlg)

public:
	CTrendBusinessDlg(ThreadManager& threadManager);   // standard constructor
	virtual ~CTrendBusinessDlg();

// Dialog Data
	enum { IDD = IDD_TREND_BUSINESS_DLG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()
	CListCtrl m_businessList;
	CComboBox m_contractCombo;
	CEdit m_maxGainEdit;
	CEdit m_maxLossEdit;
	CEdit m_openQuantityEdit;
	virtual BOOL OnInitDialog();
	afx_msg void OnBnClickedBtnAdd();
	afx_msg void OnBnClickedBtnModify();
	afx_msg void OnLvnKeydownBusinessList(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnLvnItemchangedBusinessList(NMHDR *pNMHDR, LRESULT *pResult);

	virtual void OnOK();
	virtual void OnCancel();
private:
	void InitComboData();
	void InitControls(TrendArgument const& argument);

	void InitContractSel(int contract);

	void InitBusinessList();

	bool Validate();
	void UpdateArgument();

	int GetCommandType(WORD key);
	void OnCommand(Command const& cmd);

	TrendBusiness* AddBusiness(TrendArgument const& argument);
	int GetBusinessIndex(TrendBusiness* business) const;

	void InsertBusiness(TrendBusiness* business);
	void UpdateBusiness(int index,TrendArgument const& argument);

	void HandlerShortcuts(int index, WORD key);

	void TestMarkets();

	ThreadManager& m_threadManager;
	FastBlockQueue::FastBlockQueuePtr m_uiQueue;
	QueueContext m_queueContext;

	ContractCodes const& m_contracts;
	SYSTEMTIME m_startTime;
	TrendArgument m_argument;

	std::map<TrendBusiness*,int> m_businessIndexMap;

	int m_notifyColumnPosition;

public:
	afx_msg void OnTimer(UINT_PTR nIDEvent);
private:
	CComboBox m_minuteCombo;
};
